package com.enjoyor.soa.traffic.frame.support.bean;

import com.alibaba.fastjson.JSONObject;
import com.enjoyor.soa.traffic.frame.support.util.CommonUtil;
import com.enjoyor.soa.traffic.util.helper.MapHelper;

import com.enjoyor.soa.traffic.util.pojo.Page;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class ParamObject {
    public String data;
    private Map<String, Object> dataMap;
    public String token;
    public String systemKey;
    public String callback;
    public Object dto;
    @SuppressWarnings("rawtypes")
    public Page page;
    public String orderSeq;

    public ParamObject() {
    }

    public String getData() {
        return this.data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getSystemKey() {
        return this.systemKey;
    }

    public void setSystemKey(String systemKey, HttpServletRequest request) {
        String sessionSystemKey = (String) request.getSession().getAttribute("const_systemkey");
        if (systemKey != null && !systemKey.equals("")) {
            this.systemKey = systemKey;
        } else if (sessionSystemKey != null && !sessionSystemKey.equals("")) {
            this.systemKey = sessionSystemKey;
        } else {
            Cookie[] cookies = request.getCookies();
            Cookie[] var8 = cookies;
            int var7 = cookies.length;

            for (int var6 = 0; var6 < var7; ++var6) {
                Cookie cookie = var8[var6];
                if ("systemKey".equals(cookie.getName())) {
                    this.systemKey = cookie.getValue();
                }
            }
        }

    }

    public String getToken() {
        return this.token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public void setToken(String token, HttpServletRequest request) {
        String sessionToken = (String) request.getSession().getAttribute("const_token");
        token = request.getHeader("token") == null ? request.getParameter("token") : request.getHeader("token");
        if (token != null && !token.equals("")) {
            this.token = token;
        } else if (sessionToken != null && !sessionToken.equals("")) {
            this.token = sessionToken;
        } else {
            Cookie[] cookies = request.getCookies();
            Cookie[] var8 = cookies;
            int var7 = cookies.length;

            for (int var6 = 0; var6 < var7; ++var6) {
                Cookie cookie = var8[var6];
                if ("token".equals(cookie.getName())) {
                    this.token = cookie.getValue();
                }
            }
        }

    }

    public String getCallback() {
        return this.callback;
    }

    public void setCallback(String callback) {
        this.callback = callback;
    }

    public Object getDto() {
        return this.dto;
    }

    public void setObject(Object dto) {
        this.dto = dto;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void setObject(Class bean) {
        try {
            this.dto = MapHelper.Str2Bean(this.data, bean);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }

    @SuppressWarnings("rawtypes")
    public Page getPage() {
        return this.page;
    }

    @SuppressWarnings("rawtypes")
    public void setPage(Page page) {
        this.page = page;
    }

    public void setPage() {
        this.setPage(CommonUtil.getPageInfo(this.data));
    }

    public String getOrderSeq() {
        return this.orderSeq;
    }

    public void setOrderSeq(String orderSeq) {
        this.orderSeq = orderSeq;
    }

    public void setOrderSeq() {
        if (this.data != null && !this.data.equals("")) {
            try {
                JSONObject json = JSONObject.parseObject(this.data);
                this.orderSeq = json.getString("orderSeq");
            } catch (Exception var2) {
                ;
            }
        }

    }

    public Map<String, Object> getDataMap() {
        return this.dataMap;
    }

    public void setDataMap(Map<String, Object> dataMap) {
        this.dataMap = dataMap;
    }
}
